package com.asset.web.asset;

import com.asset.pojo.AssetHandle;
import com.asset.service.HandleService;
import com.asset.util.PageResult;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * @author 11725
 */
@RestController
@RequestMapping("/handle")
public class HandleController {

    @Resource
    private HandleService handleService;

    @GetMapping("/list")
    public ResponseEntity<PageResult<AssetHandle>> selectByPage(
            @RequestParam("page") Integer page,
            @RequestParam("rows") Integer rows,
            @RequestParam("depaId") Long depaId,
            @RequestParam(value = "status", required = false) List<Integer> statusList
    ) {
        return ResponseEntity.ok(handleService.selectByPage(page, rows, depaId, statusList));
    }

    /**
     * 新增处置记录
     * @param record    AssetHandle 对象
     * @return
     */
    @PostMapping
    public ResponseEntity<Void> insert(@RequestBody @Valid AssetHandle record) {
        handleService.insert(record);
        return ResponseEntity.status(HttpStatus.CREATED).build();
    }

    /**
     * 更新审批状态
     * @param record    AssetHandle 对象
     * @return
     */
    @PutMapping
    public ResponseEntity<Void> updateStatus(@RequestBody AssetHandle record) {
        handleService.updateStatus(record);
        return ResponseEntity.status(HttpStatus.NO_CONTENT).build();
    }
}
